package com.tedu.bill.demo1;

import java.util.Objects;

/**
 * Author：毕龙
 * Date: 2024/5/21 14:17
 */
public class Worker {
    private String name;
    private double salary;

    public Worker(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }
    private static int count;
    @Override
    public boolean equals(Object o) {
        System.out.println("equals方法执行"+ count++);
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Worker worker = (Worker) o;
        return Double.compare(salary, worker.salary) == 0 && Objects.equals(name, worker.name);
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", salary=" + salary +
                '}';
    }

    @Override
    public int hashCode() {
        int result = 0;
        result = (int) (name.hashCode() + salary);
       return result;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }
}
